class Solution {
public:
string longestCommonPrefix(vector<string>& strs) {
    string res;
    for (int i = 0; i < strs[0].size(); ++i)
    {
        int flag = 1;
        char s = strs[0][i];
        for (int j = 0; j < strs.size(); ++j)
        {
            if (s != strs[j][i]) { flag = 0; break; }
            if (j == strs.size() - 1)
                res.push_back(strs[j][i]);
        }
        if (flag == 0)break;
    }
    return res;
}
};
